package com.project.pudongdata.service.impl;


import com.project.pudongdata.config.AuthenticationProperties;
import com.project.pudongdata.service.AuthenticationService;
import com.project.pudongdata.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class AuthenticationServiceImpl implements AuthenticationService {
    @Resource
    private AuthenticationProperties authenticationProperties; //用户名密码配置
    @Override
    public boolean check(String userName, String password) {
        log.info("用户名密码验证开始");
        if(authenticationProperties != null
                && authenticationProperties.getList() != null
                && !authenticationProperties.getList().isEmpty()) {
            for (AuthenticationProperties.UserItem item : authenticationProperties.getList()) {
                if (item.getUserName().equals(userName) && item.getPassword().equals(password)) {
                    log.info("用户名密码验证成功");
                    return true;

                }
            }
        }
        return false;
    }


    /**
     *
     * @param userName
     * @param password
     * @return
     */
    public String getSign(String userName, String password){
        return JwtUtil.getToken(userName,password);
    }
}
